<!--
 The BSD 3-Clause License

 Copyright 2022 - DATATRONiQ GmbH (https://datatroniq.com)
 Copyright (c) 2018-2022 Klaus Landsdorf (http://node-red.plus/)
 All rights reserved.
 node-red-contrib-iiot-opcua
-->

<script type="text/javascript">
  RED.nodes.registerType('OPCUA-IIoT-Server-Command', {
    category: 'IIoT',
    color: '#ABCDEF',
    defaults: {
      commandtype: {value: "", required: true},
      nodeId: {value: ""},
      name: {value: ""}
    },
    inputs: 1,
    outputs: 1,
    align: "left",
    icon: "icon.png",
    label: function () {
      return this.name || "S-CMD";
    },
    labelStyle: function () {
      return this.name ? "node_label_italic" : "";
    },
    oneditprepare: function () {
      let node = this

      let commandTypeCheckbox = $("#node-input-commandtype")
      let nodeIdRow = $("#node-input-nodeId-row")

      commandTypeCheckbox.change(function () {
        if ($(this).val() !== 'restart') {
          nodeIdRow.show();
        } else {
          nodeIdRow.hide();
        }
      })
    }
  });
</script>

<script type="text/x-red" data-template-name="OPCUA-IIoT-Server-Command">
    <div class="form-row">
        <label for="node-input-commandtype"><i class="icon-tasks"></i>
        <span data-i18n="opcua-iiot-contrib.label.commandtype"></span></label>
        <select type="text" id="node-input-commandtype">
            <option value="restart">Restart</option>
            <option value="deleteNode">Delete ASO</option>
        </select>
    </div>
    <div class="form-row" id="node-input-nodeId-row">
        <label for="node-input-nodeId"><i class="icon-tasks"></i> <span data-i18n="opcua-iiot-contrib.label.nodeId"></span></label>
        <input type="text" id="node-input-nodeId" placeholder="ns=1;s=MySwitch or ns=1;i=1234">
    </div>
    <div class="form-row">
        <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
        <input type="text" id="node-input-name" placeholder="">
    </div>
</script>

<script type="text/x-red" data-help-name="OPCUA-IIoT-Server-Command">
    <h2>OPC UA IIoT Server Commands</h2>

    <p>That nodes is to build event driven command injects to the server.</p>
</script>
